package cn.wjdiankong.levideo.dialog;

import java.io.File;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import cn.wjdiankong.levideo.R;
import cn.wjdiankong.levideo.data.LevideoData;
import cn.wjdiankong.levideo.utils.UIUtil;
import cn.wjdiankong.levideo.utils.Utils;
import cn.wjdiankong.levideo.view.LevideoDialog;

public class VideoInfoDialog {
	private Context mActivity;
	private View parentView;
	private LevideoDialog dialog;
	private TextView durationTxt, saveTimeTxt, locationTxt, sizeTxt;
	
	@SuppressLint("InflateParams")
	public VideoInfoDialog(Activity act){
		mActivity = act;
		
		if(parentView == null){
			parentView = LayoutInflater.from(mActivity.getApplicationContext()).inflate(R.layout.dialog_video_info, null);
		}
		if(dialog == null){
			dialog = new LevideoDialog(mActivity, parentView, UIUtil.dip2px(mActivity.getApplicationContext(), 300), 0);
		}
		
		durationTxt = (TextView) parentView.findViewById(R.id.duration_txt);
		saveTimeTxt = (TextView) parentView.findViewById(R.id.savetime_txt);
		locationTxt = (TextView) parentView.findViewById(R.id.location_txt);
		sizeTxt = (TextView) parentView.findViewById(R.id.size_txt);
	}
	
	public void setLevideoData(LevideoData data){
		if(TextUtils.isEmpty(Utils.formatDuration(data.videoDuration))){
			durationTxt.setText("视频时长: 00:15");
		}else{
			durationTxt.setText("视频时长: "+Utils.formatDuration(data.videoDuration));
		}
		saveTimeTxt.setText("保存时间: "+Utils.formatTimeDetailStr(data.createTime));
		File file = new File(data.videoPlayUrl);
		if(file.exists()){
			locationTxt.setText(data.videoPlayUrl);
			sizeTxt.setText("视频大小: "+Utils.formatSize(file.length()));
		}else{
			locationTxt.setVisibility(View.GONE);
			sizeTxt.setVisibility(View.GONE);
		}
	}
	
	public void show(){
		dialog.show();
	}
	
}
